package com.msameer.gwttutor.client;

import com.google.gwt.activity.shared.ActivityManager;
import com.google.gwt.activity.shared.ActivityMapper;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.place.shared.Place;
import com.google.gwt.place.shared.PlaceController;
import com.google.gwt.place.shared.PlaceHistoryHandler;
import com.google.gwt.user.client.ui.RootLayoutPanel;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class gwttutor implements EntryPoint {
	ClientFactory clientFactory = GWT.create(ClientFactory.class);
    private Place defaultPlace = new HomePlace(null);
    private Shell appWidget = new Shell(clientFactory);
    
    public void onModuleLoad() {
        EventBus eventBus = clientFactory.getEventBus();
        PlaceController placeController = clientFactory.getPlaceController();

        // Start ActivityManager for the main widget with our ActivityMapper
        ActivityMapper activityMapper = new AppActivityMapper(clientFactory);
        ActivityManager activityManager = new ActivityManager(activityMapper, eventBus);
        activityManager.setDisplay(appWidget);

        // Start PlaceHistoryHandler with our PlaceHistoryMapper
        AppPlaceHistoryMapper historyMapper= GWT.create(AppPlaceHistoryMapper.class);
        PlaceHistoryHandler historyHandler = new PlaceHistoryHandler(historyMapper);
        historyHandler.register(placeController, eventBus, defaultPlace);
       
        RootLayoutPanel.get().add(appWidget);
//        appWidget.setTitle("Title Title Title");
//        appWidget.setSize("100", "100");
//        appWidget.setVisible(true);
        // Goes to the place represented on URL else default place
        historyHandler.handleCurrentHistory();	
    }
}
